package com.example.demo.controller;

import com.example.demo.common.AjaxResult;
import com.example.demo.common.UserSessionUtils;
import com.example.demo.entity.Articleinfo;
import com.example.demo.entity.SystemLog;
import com.example.demo.entity.Userinfo;
import com.example.demo.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/log")
public class LogController {
    @Autowired
    private LogService logService;

    @RequestMapping("/getLog")
    public AjaxResult getLog(HttpServletRequest request) {
        Userinfo userinfo = UserSessionUtils.getUser(request);
        if(userinfo == null || !userinfo.getUsername().equals("admin")){
            return AjaxResult.fail(-1,"非法请求");
        }

        List<SystemLog> list = logService.getLogList();

        return AjaxResult.success(list);
    }

}
